package com.chuangjiangx.member.stored.ddd.domain.model;

import com.chuangjiangx.dddbase.Entity;
import com.chuangjiangx.domain.shared.model.Enable;
import com.chuangjiangx.member.basic.ddd.domain.model.MerchantId;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author 李孝延
 * @Date 2018/1/19 15:40
 **/
@Getter
@Setter
@NoArgsConstructor
public class MbrRechargeRule extends Entity<MbrRechargeRuleId> {
    /**
     * 储值规则名称
     */
    private String name;

    /**
     * 金额
     */
    private BigDecimal amount;

    /**
     * 赠送积分
     */
    private Long giftScore;

    /**
     * 赠送金额
     */
    private BigDecimal giftAmount;

    /**
     * 卡券编号
     */
    private String couponNumber;

    /**
     * 赠送卡券名称
     */
    private String giftCoupon;

    /**
     * 是否启用
     */
    private Enable enable;

    /**
     * 是否删除
     */
    private IsDelete isDelete;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 商户id
     */
    private MerchantId merchantId;


    /**
     * 赠送类型
     */
    private MbrGiftType mbrGiftType;

    /*public MbrRechargeRule(BigDecimal amount, Long giftScore, BigDecimal giftAmount,
                           String couponNumber, String giftCoupon, MerchantId merchantId,
                           MbrGiftType mbrGiftType, Enable enable) {

        this.amount = amount;
        this.giftScore = giftScore;
        this.giftAmount = giftAmount;
        this.giftCoupon = giftCoupon;
        this.couponNumber = couponNumber;
        this.createTime = new Date();
        this.merchantId = merchantId;
        if (MbrGiftType.AMOUNT.equals(mbrGiftType)) {
            this.name = "充" + amount + "元赠送" + giftAmount + "元";
        } else if (MbrGiftType.SCROE.equals(mbrGiftType)){
            this.name = "充" + amount + "元赠送" + giftScore + "积分";
        } else {
            this.name = "充" + amount + "元赠送" + giftCoupon + "券";
        }
        this.mbrGiftType = mbrGiftType;
        this.enable = enable;
        this.isDelete();
    }*/

    public static final MbrRechargeRule custom(BigDecimal amount){
        MbrRechargeRule rule = new MbrRechargeRule();
        rule.amount = amount;
        rule.name = "自定义储值";
        rule.setId(new MbrRechargeRuleId(-1));
        rule.setGiftAmount(BigDecimal.ZERO);
        rule.setGiftScore(0L);
        rule.setMbrGiftType(MbrGiftType.CUSTOMIZE);
        rule.enable = Enable.ENABLE;
        return rule;
    }
    public MbrRechargeRule(String name,
                           BigDecimal amount,
                           Long giftScore,
                           BigDecimal giftAmount,
                           String couponNumber,
                           String giftCoupon,
                           Enable enable,
                           IsDelete isDelete,
                           Date createTime,
                           Date updateTime,
                           MerchantId merchantId,
                           MbrGiftType mbrGiftType) {
        this.name = name;
        this.amount = amount;
        this.giftAmount = giftAmount;
        this.giftCoupon = giftCoupon;
        this.couponNumber = couponNumber;
        this.mbrGiftType = mbrGiftType;
        this.enable = enable;
        this.giftScore = giftScore;
        this.isDelete = isDelete;
        this.createTime = createTime;
        this.updateTime = updateTime;
        this.merchantId = merchantId;
    }

    /**
     * 储值规则是否可以
     * @return true 可用，false 不可用
     */
    public boolean isEnable(){
        if(Enable.ENABLE.equals(this.enable)){
            return true;
        }
        return false;
    }

    /**
     * 启用
     */
    public void enable() {
        if (this.enable == null || this.enable.equals(Enable.DISABLE)) {
            this.enable = Enable.ENABLE;
        }
    }

    /**
     * 不删除
     */
    public void isDelete() {
        if (this.isDelete == null || this.isDelete.equals(IsDelete.DELETE)) {
            this.isDelete = IsDelete.NOTDELETE;
        }
    }
}
